package com.yicong.ants.view.dialog;

import android.content.Context;
import android.view.View;

import com.cchao.simplelib.core.AndroidHelper;
import com.cchao.simplelib.core.UiHelper;
import com.yicong.ants.R;
import com.yicong.ants.utils.DisplayUtils;

/**
 * 获取验证码
 *
 * @author LinDingQiang
 * @description
 * @time 4/17/21 9:51 PM
 * @email dingqiang.l
 */
public class VoucherCodeDialog extends BaseNiceDialog {
    private String voucherCode;

    public static VoucherCodeDialog newInstance(Context context) {
        VoucherCodeDialog dialog = new VoucherCodeDialog();
        dialog.setOutCancel(false)
                .setWidth(DisplayUtils.px2dp(context, (float) (UiHelper.getScreenWidth() * 0.8)))
                .setDimAmount(0.5f);
        return dialog;
    }

    public VoucherCodeDialog setVoucherCode(String voucherCode) {
        this.voucherCode = voucherCode;
        return this;
    }

    @Override
    public int intLayoutId() {
        return R.layout.dialog_voucher_code;
    }

    @Override
    public void convertView(NiceViewHolder holder, BaseNiceDialog dialog) {
        holder.getView(R.id.close).setOnClickListener(view -> dismiss());
        holder.setText(R.id.voucher_code, voucherCode)
                .setOnClickListener(R.id.btn_copy, v -> {
                    AndroidHelper.setClipboardData(voucherCode, () -> {
                        dismiss();
                        UiHelper.showToast("凭证码已复制");
                    });
                });
    }
}
